<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
        }

        ul {
            display: flex;
            flex-wrap: wrap;
        }

        li {
            width: 23%;
            margin: 1%;
            text-align: center;
        }

        img {
            width: 80%;
            height: 300px;
        }
    </style>
</head>

<body>

    <h1>商品列表</h1>

    <ul>
        <!-- <li>
            <a href="">
                <img src="" alt="">
                <h3></h3>
                <p></p>
                <strong></strong>
            </a>
        </li> -->
    </ul>


    <script src="../js/ajax.js"></script>
    <script src="../js/tools.js"></script>
    <script>


        ajax({
            type: 'get',
            url: 'http://192.168.58.25/php/list.php',
            success: res => {
                console.log(res);
                const arr = res.data;
                // 渲染页面
                render(arr)
            }
        })


        function render(arr) {
            let html = '';
            arr.forEach(item => {
                html += `
                <li>
                    <a href="./06_detail.html?yy=${item.goods_id}">
                        <img src="${item.goods_img}" alt="">
                        <h3>${item.goods_title}</h3>
                        <p>${item.goods_des}</p>
                        <strong>${item.goods_price}</strong>
                    </a>
                </li>
                `
            })

            $('ul').innerHTML = html;
        }




        // 商品列表进入商品详情页   需要把id带过去

        //   方法1   给a绑定点击事件   把id存入localStorage

        //   方法2   通过地址栏携带id  在跳转到详情页的地址后面拼接问号  ?id=    

    </script>

</body>

</html>